<?php
/**
 *UserController
 * @author li ming
 * @date 2021-10-12
 */
namespace Modules\User\Http\Controllers\Api;

use Modules\User\Services\Api\UserAddressServices;

class UserAddressController extends ApiBaseController
{
    private $services;

    /**
     * @param UserAddressServices $userServices
     */
    public function __construct(UserAddressServices $userServices)
    {
        $this->services = $userServices;
    }

    /**
     * 获取地区列表
     * @return mixed
     */
    public function district()
    {
        try {
            $result = $this->services->getArea();
            return $this->success($result);
        } catch (\Exception $e) {
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 地址列表
     * @author li ming
     * @date 2021-10-12
     */
    public function pageList()
    {
        $result = $this->services->getPageList();
        return $this->success($result);
    }

    /**
     * 新增地址
     * @return mixed
     */
    public function add()
    {
        try {
            $this->services->add();
            return $this->success([],"新增地址成功");
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 新增授权获取的地址
     * @return mixed
     */
    public function empowerAdd()
    {
        try {
            $this->services->empowerAdd();
            return $this->success([],"新增地址成功");
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 编辑地址
     * @return mixed
     */
    public function edit()
    {
        try {
            $result = $this->services->edit();
            return $this->success($result, "更新地址成功");
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 设置默认地址
     * @return mixed
     */
    public function default()
    {
        try {
            $this->services->saveStatus("save_default");
            return $this->success([], "设置默认地址成功");
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }

    /**
     * 删除
     * @return mixed
     */
    public function del()
    {
        try {
            $this->services->saveStatus("del");
            return $this->success([], "删除地址成功");
        } catch (\Exception $e){
            return $this->failed($e->getMessage());
        }
    }
}